/*
 * AdimGUI.java
 *
 * Created on Oct 29, 2010, 2:29:46 PM
 */

package br.ic.ufal.view;

import br.ufal.ic.dao.UserDAO;
import br.ufal.ic.user.User;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Marcos Paulo
 */
public class AdimGUI extends javax.swing.JFrame {

    public UserDAO userDAO;

    /** Creates new form AdimGUI */
    public AdimGUI(UserDAO userDAO) {

        this.userDAO = userDAO;
        initComponents();

//        ((DefaultTableModel)jTable1.getModel()).addRow(new String[]{"haha" , "bebe"});
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "nome", "senha"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(37, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jTabbedPane1.addTab("Usuarios cadastrados", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 408, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//    /**
//    * @param args the command line arguments
//    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new AdimGUI(null).setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    //TODO metodo temporario, usar padrão observer para atualizar
    public void updateTableRows() {
        DefaultTableModel tableModel = (DefaultTableModel)jTable1.getModel();
        System.out.println(tableModel.getRowCount());

        for(int i = 0; i < tableModel.getRowCount(); i++) {
            tableModel.removeRow(i);
        }

        for(User user: userDAO.findAll()) {
            tableModel.addRow(new String[]{user.getNickName(), user.getPassword()});
        }
        
    }

//    public void update(Observable o, Object arg) {
//        DefaultTableModel tableModel = (DefaultTableModel)jTable1.getModel();
//        System.out.println("jshdjshj");
//
//        System.out.println(tableModel.getRowCount());
//    }

}
